﻿using B.S.BasicData.Api.Read.Application.Command.RBAC;
using B.S.BasicData.Domian.Entities.Account;
using B.S.BasicData.Domian.Entities.RBAC;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interface;
using MediatR;
using System.Data;

namespace B.S.BasicData.Api.Read.Application.Handler.RBAC
{
    public class RoleUserHandler : IRequestHandler<RoleUserCommand, ApiResult<List<AccountModel>>>
    {
        private readonly IBaseRepository<AccountModel> roelRepo;

        public RoleUserHandler(IBaseRepository<AccountModel> roelRepo)
        {
            this.roelRepo = roelRepo;
        }
        public Task<ApiResult<List<AccountModel>>> Handle(RoleUserCommand request, CancellationToken cancellationToken)
        {
           var res=new ApiResult<List<AccountModel>>();
            var role= roelRepo.GetAll().OrderByDescending(x => x.Id).Where(x => !x.IsDel).ToList();
            res.Message = "查询成功";
            res.Code=ApiEnum.Ok;
            res.Data = role.ToList();
            return Task.FromResult(res);
        }
    }
}
